var http = require('http');
var sha1 = require('sha1');
var util = require('util');
var url = require('url');
var qs = require('querystring');
http.createServer(function(req,res){
    var pathname = url.parse(req.url).pathname;
    if (pathname == '/weixin/test'){
        var query = url.parse(req.url,true).query;
        var signature = query.signature;
        var timestamp = query.timestamp;
        var nonce = query.nonce;
        var echostr = query.echostr;
        var token = 'pengloo53';
        var array = new Array (token,timestamp,nonce);
        array.sort();
        var arraystring = array.join('');
        arraystring = sha1(arraystring);
        if (arraystring == signature){
            console.log("验证成功！");
            res.writeHeader(200,{"Content-Type":"text/html"});
            res.end(echostr);
            return true; 
        }else{
            return false;
        }
    }
}).listen(9090);
console.log("正在验证...");
